package com.whmnx.main.ui.adapter;

import android.content.Context;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.widget.EditText;

import androidx.lifecycle.ViewModel;

import com.classic.adapter.BaseAdapterHelper;
import com.classic.adapter.CommonRecyclerAdapter;
import com.whmnx.base.bean.ProductBean;
import com.whmnx.base.utils.ImageUtil;
import com.whmnx.main.R;
import com.whmnx.main.ui.model.CommodityModel;

import me.goldze.mvvmhabit.utils.ToastUtils;

/**
 * author : huang
 * date   : 2020/10/14 0014 17:00
 * version: 1.0
 * @author Administrator
 */
public class PingDanAdapter extends CommonRecyclerAdapter<ProductBean.SpecModelBean> {

   private CommodityModel mVodel;
    public PingDanAdapter(Context context, CommodityModel commodityModel) {
        super(context, R.layout.item_add_com2);
        this.mVodel = commodityModel;
    }


    @Override
    public void onUpdate(BaseAdapterHelper helper, ProductBean.SpecModelBean item, int position) {
        if (TextUtils.isEmpty(item.ProductSPEC_Name)){
            helper.setText(R.id.tv1, (String) item.getProductSPEC_Name());
        }else {
            helper.setText(R.id.tv1, (String) item.ProductSPEC_Name);
        }
        if (TextUtils.isEmpty(item.ProductSPEC_Price)){
            helper.setText(R.id.tv2, (String) item.getProductSPEC_Price());
        }else {
            helper.setText(R.id.tv2, (String) item.ProductSPEC_Price);
        }

           //helper.setText(R.id.tv2, (String) item.ProductSPEC_Price);
           if (TextUtils.isEmpty(item.ProductSPEC_GroupPrice) ){
               helper.setText(R.id.et_pin, (String) item.getProductSPEC_GroupPrice());
           }else {
               helper.setText(R.id.et_pin, (String) item.ProductSPEC_GroupPrice);
           }


        EditText etPing = helper.getView(R.id.et_pin);
        etPing.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                item.setProductSPEC_GroupPrice(s.toString().trim());
                mVodel.specModelBeans.set(position,item);
            }
        });
    }
}
